package com.hskn.hss.module.clock.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.carTrack.mapper.CarTrackMapper;
import com.hskn.hss.module.carviolation.entity.CarViolation;
import com.hskn.hss.module.clock.entity.Clock;
import com.hskn.hss.module.clock.mapper.ClockMapper;
import com.hskn.hss.module.clock.service.IClockService;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-17
 */
@Slf4j
@RestController
@RequestMapping("/hss/clock")
public class ClockController {

    @Autowired
    private IClockService clockService;

    @SysLog(businessType = BusinessType.UPDATE, tableName = "clock", idKey = "clockId", bean = Clock.class, beanMapper = ClockMapper.class, names = "personId")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            clockService.mUpdate(params);
            return AjaxResult.success("修改成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
}

